package com.luban.bean;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;


/**
 * @author Administrator
 * 给一个class 属性 在构造的时候 传入一个class  然后返回这个传入的class
 *
 */
public class MapperFactoryBean implements FactoryBean {

	private Class MapperInterface;

	public MapperFactoryBean(Class mapperInterface) {
		MapperInterface = mapperInterface;
	}

	@Override
	public Object getObject() throws Exception {
		Object proxyInstance = Proxy.newProxyInstance(MapperFactoryBean.class.getClassLoader(), new Class[]{MapperInterface}, new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				System.out.println(method.getName());
				return null;
			}
		});

		return proxyInstance;
	}

	@Override
	public Class<?> getObjectType() {
		return MapperInterface;
	}
}
